1. running issue

when I directly config the testing-library/jest-dom in jest.config.js,it will come as follow:

TypeScript diagnostics (customize using [jest-config].globals.ts-jest.diagnostics option)
Property ‘toBeInTheDocument’ does not exist on type ‘Matchers‘.
read the intruduction here

2. configuring again then can use the library in global env

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// config/setup-test.js
require("@testing-library/jest-dom/extend-expect");
// jest.config.js add globals
{
globals: {
'ts-jest': {
diagnostics: false
}
},
setupFilesAfterEnv: [
"<rootDir>/config/setup-enzyme.js",
"<rootDir>/config/setup-test.js"
]
}

3. node version request

  • it will run errors when the node version under 8.make sure you have the latest node version.

4. babel-plugin-react-remove-properties

如果考量到 data-testid 被 build 後會被看見,也可以透過 babel-plugin-react-remove-properties 將 data-testid 移除。